{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Redistribute Characters to Make All Strings Equal"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #hash-table #string #counting"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #哈希表 #字符串 #计数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: makeEqual"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #重新分配字符使所有字符串都相等"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你一个字符串数组 <code>words</code>（下标 <strong>从 0 开始</strong> 计数）。</p>\n",
    "\n",
    "<p>在一步操作中，需先选出两个 <strong>不同</strong> 下标 <code>i</code> 和 <code>j</code>，其中 <code>words[i]</code> 是一个非空字符串，接着将 <code>words[i]</code> 中的 <strong>任一</strong> 字符移动到 <code>words[j]</code> 中的 <strong>任一</strong> 位置上。</p>\n",
    "\n",
    "<p>如果执行任意步操作可以使 <code>words</code> 中的每个字符串都相等，返回 <code>true</code><em> </em>；否则，返回<em> </em><code>false</code> 。</p>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>words = [\"abc\",\"aabc\",\"bc\"]\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>将 <code>words[1] 中的第一个</code> 'a' 移动到<code> words[2] 的最前面。\n",
    "使 </code><code>words[1]</code> = \"abc\" 且 words[2] = \"abc\" 。\n",
    "所有字符串都等于 \"abc\" ，所以返回 <code>true</code> 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>words = [\"ab\",\"a\"]\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>执行操作无法使所有字符串都相等。\n",
    "</pre>\n",
    "\n",
    "<p> </p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= words.length &lt;= 100</code></li>\n",
    "\t<li><code>1 &lt;= words[i].length &lt;= 100</code></li>\n",
    "\t<li><code>words[i]</code> 由小写英文字母组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [redistribute-characters-to-make-all-strings-equal](https://leetcode.cn/problems/redistribute-characters-to-make-all-strings-equal/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [redistribute-characters-to-make-all-strings-equal](https://leetcode.cn/problems/redistribute-characters-to-make-all-strings-equal/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[\"abc\",\"aabc\",\"bc\"]', '[\"ab\",\"a\"]']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        return all(val % len(words) == 0 for key, val in Counter(''.join(words)).items())\n",
    "\n",
    "        \n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        dic = {}\n",
    "        n = len(words)\n",
    "        for word in words:\n",
    "            for ch in word:\n",
    "                if ch not in dic:\n",
    "                    dic[ch] = 1\n",
    "                else:\n",
    "                    dic[ch] += 1\n",
    "        for cnt in dic.values():\n",
    "            if cnt%n!=0:return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26   # 每种字符的频数\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n=len(words)\n",
    "        words=\"\".join(words)\n",
    "        words=collections.Counter(words)\n",
    "        for count in words.values():\n",
    "            if count%n !=0:return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        Allword = ''\n",
    "        for i in words:\n",
    "            Allword += i\n",
    "        counter = Counter(Allword)\n",
    "        n = len(words)\n",
    "        for i in counter.values():\n",
    "            if i % n != 0 :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0]*26\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] +=1\n",
    "        return all(k%n == 0 for k in cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26   # 每种字符的频数\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        Allword = ''\n",
    "        for i in words:\n",
    "            Allword += i\n",
    "        counter = Counter(Allword)\n",
    "        n = len(words)\n",
    "        for i in counter.values():\n",
    "            if i % n != 0 :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        dictionary = dict()\n",
    "        for word in words:\n",
    "            for x in word:\n",
    "                if x not in dictionary.keys():\n",
    "                    dictionary[x] = 1\n",
    "                else:\n",
    "                    dictionary[x] += 1\n",
    "        for x in dictionary.values():\n",
    "            if x % len(words) != 0:\n",
    "                return False\n",
    "        return True "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        check = {}\n",
    "        if words == [] or len(words) == 1:\n",
    "            return True\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                if j not in check:\n",
    "                    check[j] = 1\n",
    "                    continue\n",
    "                check[j] += 1\n",
    "\n",
    "        checkList = check.values()\n",
    "\n",
    "        for i in checkList:\n",
    "            if i % len(words) != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        aa = 'qwertyuiopasdfghjklzxcvbnm'\n",
    "        ss = ''.join(words)\n",
    "        if len(ss) % len(words)!=0:\n",
    "            return False\n",
    "        for s in aa:\n",
    "            if ss.count(s)%len(words)!=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        dic = {}\n",
    "        for word in words:\n",
    "            for i in word:\n",
    "                if i not in dic:\n",
    "                    dic[i] = 1\n",
    "                else:\n",
    "                    dic[i] += 1\n",
    "        for j in dic:\n",
    "            if dic[j] % n != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        Allword = ''\n",
    "        for i in words:\n",
    "            Allword += i\n",
    "        counter = Counter(Allword)\n",
    "        n = len(words)\n",
    "        for i in counter.values():\n",
    "            if i % n != 0 :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26   # 每种字符的频数\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        return all(value % len(words) == 0 for key, value in Counter(''.join(words)).items())\n",
    "        # n = len(words)\n",
    "        # cdict = {}\n",
    "        # for i in words:\n",
    "        #     for c in i:\n",
    "        #         cdict[c] = cdict.get(c,0) + 1\n",
    "        # for key, value in cdict.items():\n",
    "        #     if value % n != 0:\n",
    "        #         return False\n",
    "\n",
    "        # return True\n",
    "\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        c = sum((Counter(w) for w in words), Counter())\n",
    "        n = len(words)\n",
    "        return all(v % n == 0 for v in c.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26   # 每种字符的频数\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        s = ''.join(words)\n",
    "        n = len(words)\n",
    "        dict1=Counter(s)\n",
    "        for v in dict1.values():\n",
    "            if v%n !=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        dic={}\n",
    "        for word in words:\n",
    "            for i in range(len(word)):\n",
    "                dic[word[i]] = dic.get(word[i],0) + 1 \n",
    "        nums=[]\n",
    "        for key,value in dic.items():\n",
    "            if value % len(words) != 0:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "\n",
    " \n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        ad={}\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                ad[j]=ad.get(j,0)+1\n",
    "        for i in ad.values():\n",
    "            if i%len(words)!=0:\n",
    "                return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        S = Counter(\"\".join(words))\n",
    "        return not any(freq % len(words) for freq in S.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        c = sum((Counter(w) for w in words), Counter())\n",
    "        n = len(words)\n",
    "        return all(v % n == 0 for v in c.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        counter=dict()\n",
    "        for word in words:\n",
    "            for ch in word:\n",
    "                counter[ch]=counter.get(ch,0)+1\n",
    "        size=len(words)\n",
    "        for key in counter:\n",
    "            if counter[key]%size!=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26   # 每种字符的频数\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        dic = {}\n",
    "        for word in words:\n",
    "            for i in word:\n",
    "                if i not in dic:\n",
    "                    dic[i] = 1\n",
    "                else:\n",
    "                    dic[i] += 1\n",
    "        for j in dic:\n",
    "            if dic[j] % n != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        S = Counter(\"\".join(words))\n",
    "        return all(S[i] % len(words) == 0 for i in S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch) - ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        dic = Counter(\"\".join(words))\n",
    "        return all(v % n == 0 for v in dic.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        counter=Counter()\n",
    "        for i in words:\n",
    "            counter.update(i)\n",
    "        for j in counter.items():\n",
    "            if j[1]%len(words)!=0:\n",
    "                return False\n",
    "                break\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        c = Counter(''.join(words))\n",
    "        return all(x % n == 0 for x in c.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        size = len(words)\n",
    "        if size == 1:\n",
    "            return True\n",
    "\n",
    "        seen = {}\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                seen[c] = seen.get(c, 0) + 1\n",
    "        print(seen)\n",
    "        \n",
    "        for n in seen:\n",
    "            if seen[n] % size != 0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        zd = dict()\n",
    "        n = len(words)\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                zd[j] = zd.get(j, 0) + 1\n",
    "        print(zd)\n",
    "        return all(i%n==0 for i in zd.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        return all(val%len(words)==0 for key,val in Counter(''.join(words)).items()) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "\n",
    "        \n",
    "        n = len(words)\n",
    "\n",
    "        if n == 1:\n",
    "            return True\n",
    "            \n",
    "        s = Counter()\n",
    "        ss = ''\n",
    "\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                s[c] += 1\n",
    "                if c not in ss:\n",
    "                    ss += c\n",
    "\n",
    "        l = s[ss[0]]\n",
    "        for c in ss:\n",
    "            l = s[c]\n",
    "            if l % n != 0:\n",
    "                return  False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        size = len(words)\n",
    "        if size == 1:\n",
    "            return True\n",
    "\n",
    "        seen = {}\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                seen[c] = seen.get(c, 0) + 1\n",
    "        \n",
    "        for n in seen:\n",
    "            if seen[n] % size != 0:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        dic = {}\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                dic[j] = dic.get(j, 0) + 1\n",
    "\n",
    "        num = tuple(dic.values())[0]\n",
    "        return False not in [i % len(words) == 0 for i in dic.values()]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        w=''.join(words)\n",
    "        w=collections.Counter(w)\n",
    "        return all(i%len(words)==0 for i in w.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "\n",
    "        \n",
    "        n = len(words)\n",
    "        if n == 1:\n",
    "            return True\n",
    "        s = Counter()\n",
    "        ss = ''\n",
    "\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                s[c] += 1\n",
    "                if c not in ss:\n",
    "                    ss += c\n",
    "\n",
    "        l = s[ss[0]]\n",
    "        for c in ss:\n",
    "            l = s[c]\n",
    "            if l % n != 0:\n",
    "                return  False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        count = [0] * 26\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                count[ord(c) - ord('a')] += 1\n",
    "        for i in range(26):\n",
    "            if count[i] % len(words) != 0:\n",
    "                return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        dic = defaultdict(int)\n",
    "        for word in words:\n",
    "            for ch in word:\n",
    "                dic[ch] +=1\n",
    "        for ch,f in dic.items():\n",
    "            if f%n !=0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        a = {}\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                if j in a:\n",
    "                    a[j] += 1\n",
    "                else:\n",
    "                    a[j] = 1\n",
    "        for k,v in a.items(): \n",
    "            if v%len(words):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        dic = {}\n",
    "        for word in words:\n",
    "            for i in word:\n",
    "                if i not in dic:\n",
    "                    dic[i] = 1\n",
    "                else:\n",
    "                    dic[i] += 1\n",
    "        for j in dic:\n",
    "            if dic[j] % n != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        return all(val % len(words) == 0 for key, val in Counter(''.join(words)).items())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        Allword = ''\n",
    "        for i in words:\n",
    "            Allword += i\n",
    "        counter = Counter(Allword)\n",
    "        return all([i % len(words) == 0 for i in counter.values()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26 \n",
    "        n = len(words) \n",
    "        for wd in words :\n",
    "            for ch in wd :\n",
    "                cnt[ord(ch)-ord('a')] += 1 \n",
    "        return all(v % n == 0 for v in cnt )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        if not words:\n",
    "            return False\n",
    "        n = len(words)\n",
    "        total_counter = Counter()\n",
    "        for strs in words :\n",
    "            counter = Counter(strs)\n",
    "            total_counter += counter\n",
    "        for nums in total_counter.values():\n",
    "            if nums % n != 0 :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "\n",
    "        arr = [0] * 26\n",
    "\n",
    "        for w in words:\n",
    "            for ss in w:\n",
    "                arr[ord(ss) - 97] += 1\n",
    "        \n",
    "        for ele in arr:\n",
    "            if ele % n != 0:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        c = collections.Counter(''.join(words))\n",
    "        return all(i%len(words)==0 for i in c.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt, l = [0] * 26, len(words)  # cnt记录每种字符的频数\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(not k % l for k in cnt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from collections import Counter\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        letters = Counter(\"\".join(words))\n",
    "        print(letters)\n",
    "        for k,v in letters.items():\n",
    "            if v % len(words) != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        st=''.join(words)\n",
    "        dic=Counter(st)\n",
    "        if all(key %n ==0 for key in dic.values()):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        cntr = Counter()\n",
    "        for w in words:\n",
    "            for ch in w:\n",
    "                cntr[ch] += 1\n",
    "        return all(val % n == 0 for val in cntr.values())        \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n=len(words)\n",
    "        split_chars = [char for word in words for char in word]\n",
    "        s=Counter(split_chars)\n",
    "        for i in s.values():\n",
    "            if i%n!=0:\n",
    "                return False\n",
    "        return True\n",
    "            \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "\n",
    "        \n",
    "        n = len(words)\n",
    "        if n == 1:\n",
    "            return True\n",
    "        s = Counter()\n",
    "        ss = ''\n",
    "\n",
    "        for word in words:\n",
    "            for c in word:\n",
    "                s[c] += 1\n",
    "                if c not in ss:\n",
    "                    ss += c\n",
    "\n",
    "        l = s[ss[0]]\n",
    "        for c in ss:\n",
    "            l = s[c]\n",
    "            if l % n != 0:\n",
    "                return  False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        length=len(words)\n",
    "        t=''\n",
    "        for i in words:\n",
    "            t+=i\n",
    "        dic=Counter(t)\n",
    "        for key,val in dic.items():\n",
    "            if val%length:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "\r\n",
    "    def makeEqual(self, words: List[str]) -> bool:\r\n",
    "\r\n",
    "        se = {}\r\n",
    "        for word in words:\r\n",
    "            for c in word:\r\n",
    "                if c not in se: se[c] = 1\r\n",
    "                else: se[c] += 1\r\n",
    "        for _, v in se.items():\r\n",
    "            if v % len(words) != 0: return False\r\n",
    "        return True\r\n",
    "\r\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        return all(v % len(words) == 0 for v in Counter(\"\".join(words)).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        dic = {}\n",
    "        for i in words:\n",
    "            for j in i:\n",
    "                if j in dic:\n",
    "                    dic[j] += 1\n",
    "                else:\n",
    "                    dic[j] = 1\n",
    "        length = len(words)\n",
    "        for i in dic:\n",
    "            if dic[i]%length != 0:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26   # 每种字符的频数\n",
    "        n = len(words)\n",
    "        for wd in words:\n",
    "            for ch in wd:\n",
    "                cnt[ord(ch)-ord('a')] += 1\n",
    "        return all(k % n == 0 for k in cnt)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        Allword = ''\n",
    "        for i in words:\n",
    "            Allword += i\n",
    "        counter = Counter(Allword)\n",
    "        n = len(words)\n",
    "        for i in counter.values():\n",
    "            if i % n != 0 :\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        state = Counter() \n",
    "        for word in words :\n",
    "            state += Counter(word)\n",
    "        for _ , v in state.items():\n",
    "            if v % n != 0 :\n",
    "                return False \n",
    "        return True "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        return all([val%len(words)==0 for val in Counter(''.join(words)).values()])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        n = len(words)\n",
    "        if n == 1:\n",
    "            return True\n",
    "        ans = ''.join(words)\n",
    "        m = len(ans)\n",
    "        if m % n != 0:\n",
    "            return False\n",
    "        ans = list(ans)\n",
    "        ans.sort()\n",
    "        l = m // n\n",
    "        for i in range(l):\n",
    "            tmp = ans[i * n: (i + 1) * n]\n",
    "            if len(set(tmp)) != 1:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        s1=''\n",
    "        for i in words:\n",
    "            s1+=i\n",
    "        dict1=dict(Counter(s1))\n",
    "        for i in dict1:\n",
    "            if dict1[i]%len(words)!=0:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        c = Counter()\n",
    "        for word in words:\n",
    "            c += Counter(word)\n",
    "        return not any(number % len(words) for number in dict(c).values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        c = defaultdict(int)\n",
    "        n = len(words)\n",
    "        for w in words:\n",
    "            for ch in w:\n",
    "                c[ch] += 1\n",
    "        return all(x % n == 0 for x in c.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def makeEqual(self, words: List[str]) -> bool:\n",
    "        cnt = [0] * 26 \n",
    "        n = len(words) \n",
    "        for wd in words :\n",
    "            for ch in wd :\n",
    "                cnt[ord(ch)-ord('a')] += 1 \n",
    "        return all(False if v % n != 0 else True for v in cnt )"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
